﻿using ScFramework.Core;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//[RequireComponent(typeof(SComValues))]
[DisallowMultipleComponent]
[RequireComponent(typeof(SpriteRenderer))]
public sealed class SComBody : SComponent
{
    public List<GameObject> ColliderRootConfig = null;


    [PureValueAtrribute]
    public string Abstract="";
    [PureValueAtrribute]
    public int UserID;
    [PureValueAtrribute]
    public Vector3Int MeshPos;

    [DynamicValueAtrribute]
    string SpriteName
    {
        get =>GetComponent<SpriteRenderer>().  sprite.name;
    }
    [PureValueAtrribute]
    public bool IsFliped;
    /// <summary>
    /// 旋转角度,0,1,2,3,分别为逆时针旋转0,90,180,270°
    /// </summary>
    [PureValueAtrribute]
    public int MeshRotate;

    /// <summary>
    /// 物体所处位置,0 物理世界上,1 拼装台上,2 背包里
    /// </summary>
    [PureValueAtrribute]
    public int PresentPos;
  //  public Sprite sprite;

    public override void SInit()
    {
        base.SInit();
    }
    //[PureValueAtrribute]
    // public List<Vector3Int> SubBoxsLocalPos;


}

public enum ObjectPresentPos
{
    World=0,
    Bench=1,
    Bag=2,

    Null=3
}
public static class SComBodyEx
{
    public static Vector3Int WorldMeshPos(Vector3Int wpos,bool IsFliped, int ro, Vector3Int pos)
    {
        if (IsFliped)
        {
            pos.x *= -1;
        }

        //        int ro =(int) body.MeshRotate.Value;
        if (ro == 0) return wpos+pos;
        else if (ro == 1) return wpos+new Vector3Int(-pos.y, pos.x, pos.z);
        else if (ro == 2) return wpos+new Vector3Int(-pos.x, -pos.y, pos.z);
        else if (ro == 3) return wpos+new Vector3Int(pos.y, -pos.x, pos.z);
        else throw new System.Exception();

    }
    static int[] fx = new int[4] { 1, 0, -1, 0 };
    static int[] fy = new int[4] { 0, 1, 0, -1 };
    public static Vector3Int LocalDirPos(Vector3Int boxPos, int rotate)
    {

        var pos = boxPos;
        return new Vector3Int(pos.x + fx[rotate], pos.y + fy[rotate], pos.z);
    }

}